<!DOCTYPE html><html lang="en"><head><title>vault/CreateBankAccount</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content="../"><meta name="groc-document-path" content="vault/CreateBankAccount"><meta name="groc-project-path" content="vault/CreateBankAccount.php"><link rel="stylesheet" type="text/css" media="all" href="../assets/style.css"><script type="text/javascript" src="../assets/behavior.js"></script><body><div id="meta"><div class="file-path">vault/CreateBankAccount.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="create-bank-account-sample">Create Bank Account Sample</h1>
<p>You can store credit card details securely
with PayPal. You can then use the returned
Bank Account id to process future payments.
API used: POST /v1/vault/bank-accounts</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../bootstrap.php'</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">BankAccount</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="bank-account">Bank Account</h3>
<p>A resource representing a bank account that is
to be stored with PayPal.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/*
        {
            "account_number": "4417119669820331",
            "account_number_type": "IBAN",
            "account_type": "SAVINGS",
            "account_name": "Ramraj",
            "check_type": "PERSONAL",
            "auth_type": "WEB",
            "bank_name": "CITI",
            "country_code": "US",
            "first_name": "Ramraj",
            "last_name": "K",
            "birth_date": "1987-08-13",
            "billing_address": {
                "line1": "52 N Main ST",
                "city": "Johnstown",
                "country_code": "US",
                "postal_code": "43210",
                "state": "OH",
                "phone": "408-334-8890"
            },
            "external_customer_id": "external_id"
        }
*/</span>
<span class="hljs-variable">$bankAccount</span> = <span class="hljs-keyword">new</span> BankAccount();
<span class="hljs-variable">$bankAccount</span>-&gt;setAccountNumber(<span class="hljs-string">"4417119669820331"</span>)
    -&gt;setAccountNumberType(<span class="hljs-string">"IBAN"</span>)
    -&gt;setAccountType(<span class="hljs-string">"SAVINGS"</span>)
    -&gt;setAccountName(<span class="hljs-string">"Ramraj"</span>)
    -&gt;setCheckType(<span class="hljs-string">"PERSONAL"</span>)
    -&gt;setAuthType(<span class="hljs-string">"WEB"</span>)
    -&gt;setBankName(<span class="hljs-string">"CITI"</span>)
    -&gt;setCountryCode(<span class="hljs-string">"US"</span>)
    -&gt;setFirstName(<span class="hljs-string">"Ramraj"</span>)
    -&gt;setLastName(<span class="hljs-string">"K"</span>)
    -&gt;setBirthDate(<span class="hljs-string">"1987-08-13"</span>)
    -&gt;setExternalCustomerId(uniqid());

<span class="hljs-variable">$billingAddress</span> = <span class="hljs-keyword">new</span> \PayPal\Api\Address();
<span class="hljs-variable">$billingAddress</span>-&gt;setLine1(<span class="hljs-string">"52 N Main St"</span>)
    -&gt;setCity(<span class="hljs-string">"Johnstown"</span>)
    -&gt;setState(<span class="hljs-string">"OH"</span>)
    -&gt;setCountryCode(<span class="hljs-string">"US"</span>)
    -&gt;setPostalCode(<span class="hljs-string">"43210"</span>)
    -&gt;setPhone(<span class="hljs-string">"408-334-8890"</span>);

<span class="hljs-variable">$bankAccount</span>-&gt;setBillingAddress(<span class="hljs-variable">$billingAddress</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>For Sample Purposes Only.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$request</span> = <span class="hljs-keyword">clone</span> <span class="hljs-variable">$bankAccount</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="save-bank-account">Save bank account</h3>
<p>Creates the bank account as a resource
in the PayPal vault. The response contains
an &#39;id&#39; that you can use to refer to it
in future payments.
(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
    <span class="hljs-variable">$bankAccount</span>-&gt;create(<span class="hljs-variable">$apiContext</span>);
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY</p></div></div><div class="code"><div class="wrapper"> 	ResultPrinter::printError(<span class="hljs-string">"Create Bank Account"</span>, <span class="hljs-string">"Bank Account"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$request</span>, <span class="hljs-variable">$ex</span>);
    <span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
}</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY</p></div></div><div class="code"><div class="wrapper"> ResultPrinter::printResult(<span class="hljs-string">"Create Bank Account"</span>, <span class="hljs-string">"Bank Account"</span>, <span class="hljs-variable">$bankAccount</span>-&gt;getId(), <span class="hljs-variable">$request</span>, <span class="hljs-variable">$bankAccount</span>);

<span class="hljs-keyword">return</span> <span class="hljs-variable">$bankAccount</span>;</div></div></div></div></body></html>